package com.hangim.pce.enums;

import com.fasterxml.jackson.annotation.JsonFormat;

/**
 * 规则类型
 */
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum RuleTargetType {
    ELEMENT("ELEMENT", 1, "成分"),
    DRUG("DRUG", 2, "药品"),
    USAGE("USAGE", 3, "用量"),
    OTHER("OTHER", 0, "其他");

    // 类型
    private final String code;
    // 描述
    private final String desc;

    private final Integer num;

    RuleTargetType(final String code, final Integer num, final String desc) {
        this.code = code;
        this.desc = desc;
        this.num = num;
    }

    public static Boolean isElement(String desc) {
        RuleTargetType[] ts = RuleTargetType.values();
        if (ELEMENT.getDesc().contains(desc)) {
            return true;
        }
        return false;
    }

    public static Boolean isUsage(String desc) {
        RuleTargetType[] ts = RuleTargetType.values();
        if (USAGE.getDesc().contains(desc)) {
            return true;
        }
        return false;
    }

    public static Boolean isDrug(String desc) {
        RuleTargetType[] ts = RuleTargetType.values();
        if (DRUG.getDesc().contains(desc)) {
            return true;
        }
        return false;
    }


    public static RuleTargetType getRuleType(String code) {
        RuleTargetType[] ts = RuleTargetType.values();
        for (RuleTargetType t : ts) {
            if (t.getCode().equalsIgnoreCase(code)) {
                return t;
            }
        }
        return OTHER;
    }

    public static RuleTargetType getRuleTypeByDesc(String desc) {
        RuleTargetType[] ts = RuleTargetType.values();
        for (RuleTargetType t : ts) {
            if (t.getDesc().contains(desc)) {
                return t;
            }
        }
        return OTHER;
    }

    public String getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    public Integer getNum() {
        return num;
    }
}
